package com.greateffect.littlebud.lib.ui;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;

import com.greateffect.littlebud.lib.utils.IFileUtils;
import com.greateffect.littlebud.lib.utils.JLogUtil;

import org.apache.log4j.Level;

import java.io.File;

import de.mindpipe.android.logging.log4j.LogConfigurator;

/**
 * Created by ZengCS on 2019/1/18.
 * E-mail:zengcs@vip.qq.com
 * Add:成都市天府软件园E3
 */
public abstract class BaseSplashActivity extends AppCompatActivity {
    /**
     * 打开应用程序设置界面
     */
    protected void openAppDetailSettings() {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
        intent.setData(Uri.fromParts("package", getPackageName(), null));
        startActivity(intent);
    }

    /**
     * 初始化Log4j
     *
     * @param logPath 日志路径，例：sxw/launcher/log
     */
    protected void initLog4j(String logPath) {
        try {
            String path = IFileUtils.mkdirs(logPath);

            LogConfigurator logConfigurator = new LogConfigurator();
            logConfigurator.setFileName(path + File.separator + "log.txt");
            logConfigurator.setRootLevel(Level.INFO);
            logConfigurator.setLevel("org.apache", Level.INFO);
            logConfigurator.setFilePattern("%d %-5p [%c{2}]-[%L] %m%n");
            logConfigurator.setMaxFileSize(1024 * 1024 * 2);
            logConfigurator.setImmediateFlush(true);
            logConfigurator.configure();
        } catch (Exception e) {
            e.printStackTrace();
            JLogUtil.e(e);
        }
    }
}
